import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:laohuangli/api.dart';
import 'package:laohuangli/bottom.dart';

class ContentPage extends StatefulWidget {
  ContentPage({Key key, this.data}) : super(key: key);
  final data;

  @override
  _ContentPageState createState() => _ContentPageState();
}

class _ContentPageState extends State<ContentPage> {
  Color _mainColor = Color(0xFFc55144);
  Color _bgColor = Color(0xFFede7de);

  @override
  void initState() {
    super.initState();
  }

  getSingle(title, content) {
    return Container(
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(
            color: _mainColor,
            width: 2,
            style: BorderStyle.solid,
          ),
          right: BorderSide(
            color: _mainColor,
            width: 2,
            style: BorderStyle.solid,
          ),
          left: BorderSide(
            color: _mainColor,
            width: 2,
            style: BorderStyle.solid,
          ),
        ),
      ),
      child: Row(
        children: [
          Container(
            width: 90,
            height: 40,
            padding: EdgeInsets.all(5),
            decoration: BoxDecoration(
              border: Border(
                right: BorderSide(
                  color: _mainColor,
                  width: 2,
                  style: BorderStyle.solid,
                ),
              ),
            ),
            child: Center(
              child: Text(
                title,
                style: TextStyle(
                  color: _mainColor,
                  fontSize: 16,
                  fontWeight: FontWeight.w600,
                ),
              ),
            ),
          ),
          SizedBox(width: 15),
          Expanded(
            child: Text(
              content,
              style: TextStyle(
                color: _mainColor,
                fontSize: 12,
                fontWeight: FontWeight.w600,
              ),
            ),
          ),
          SizedBox(width: 15)
        ],
      ),
    );
  }

  listRender(data) {
    List<Widget> list = [];
    for (var i = 0; i < data.length; i++) {
      var item = data[i];
      list.add(getSingle(item['title'], item['content']));
    }
    return list;
  }

  @override
  Widget build(BuildContext context) {
    return widget.data == null
        ? Container(
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height - 130,
            color: _bgColor,
            child: Center(child: CircularProgressIndicator()),
          )
        : Container(
            padding: EdgeInsets.all(10),
            width: MediaQuery.of(context).size.width,
            decoration: BoxDecoration(
              color: _bgColor,
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Container(
                  width: MediaQuery.of(context).size.width,
                  height: 80,
                  decoration: BoxDecoration(
                    image: DecorationImage(
                      image: AssetImage("assets/images/border.png"),
                      fit: BoxFit.fill,
                    ),
                  ),
                  child: Center(
                    child: Text(
                      widget.data['details'][0]['content'],
                      style: TextStyle(
                        color: _bgColor,
                        fontSize: 17,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    SizedBox(width: 30),
                    Container(
                      width: 16,
                      child: Text(
                        widget.data['scxs'][0],
                        style: TextStyle(
                          color: _mainColor,
                          fontSize: 16,
                          fontWeight: FontWeight.w600,
                        ),
                        maxLines: 100,
                      ),
                    ),
                    Expanded(
                      child: Center(
                        child: Text(
                          widget.data['day'],
                          style: TextStyle(
                            color: _mainColor,
                            fontSize: MediaQuery.of(context).size.width - 170,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                      ),
                    ),
                    Container(
                      width: 16,
                      child: Text(
                        widget.data['scxs'][1],
                        style: TextStyle(
                          color: _mainColor,
                          fontSize: 16,
                          fontWeight: FontWeight.w600,
                        ),
                        maxLines: 100,
                      ),
                    ),
                    SizedBox(width: 30),
                  ],
                ),
                Row(
                  children: [
                    Container(
                      width: 100,
                      height: 60,
                      padding: EdgeInsets.all(2),
                      decoration: BoxDecoration(
                        border: Border.all(
                          color: _mainColor,
                          width: 2,
                          style: BorderStyle.solid,
                        ),
                      ),
                      child: Center(
                        child: Text(
                          widget.data['details'][5]['content'],
                          style: TextStyle(
                            color: _mainColor,
                            fontSize: 16,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        width: 100,
                        height: 60,
                        decoration: BoxDecoration(
                          color: _mainColor,
                        ),
                        child: Column(
                          children: [
                            Container(
                              height: 30,
                              decoration: BoxDecoration(
                                border: Border(
                                  bottom: BorderSide(
                                    color: _bgColor,
                                    width: 2,
                                    style: BorderStyle.solid,
                                  ),
                                ),
                              ),
                              child: Center(
                                child: Text(
                                  widget.data['details'][1]['content'],
                                  style: TextStyle(
                                    color: _bgColor,
                                    fontSize: 15,
                                    fontWeight: FontWeight.w600,
                                  ),
                                ),
                              ),
                            ),
                            Container(
                              height: 30,
                              decoration: BoxDecoration(
                                color: _bgColor,
                                border: Border(
                                  bottom: BorderSide(
                                    color: _mainColor,
                                    width: 2,
                                    style: BorderStyle.solid,
                                  ),
                                ),
                              ),
                              child: Center(
                                child: Text(
                                  widget.data['details'][2]['content'],
                                  style: TextStyle(
                                    color: _mainColor,
                                    fontSize: 16,
                                    fontWeight: FontWeight.w600,
                                  ),
                                ),
                              ),
                            )
                          ],
                        ),
                      ),
                    ),
                    Container(
                      width: 100,
                      height: 60,
                      decoration: BoxDecoration(
                        border: Border.all(
                          color: _mainColor,
                          width: 2,
                          style: BorderStyle.solid,
                        ),
                      ),
                      child: Center(
                        child: Text(
                          widget.data['details'][4]['content'],
                          style: TextStyle(
                            color: _mainColor,
                            fontSize: 16,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                      ),
                    )
                  ],
                ),
                Container(
                  decoration: BoxDecoration(
                    border: Border(
                      bottom: BorderSide(
                        color: _mainColor,
                        width: 2,
                        style: BorderStyle.solid,
                      ),
                      right: BorderSide(
                        color: _mainColor,
                        width: 2,
                        style: BorderStyle.solid,
                      ),
                      left: BorderSide(
                        color: _mainColor,
                        width: 2,
                        style: BorderStyle.solid,
                      ),
                    ),
                  ),
                  child: Row(
                    children: [
                      Container(
                        width: 40,
                        height: 40,
                        margin: EdgeInsets.all(15),
                        decoration: BoxDecoration(
                          color: Color(0xFF238F60),
                          borderRadius: BorderRadius.circular(100),
                        ),
                        child: Center(
                          child: Text(
                            '宜',
                            style: TextStyle(
                              color: _bgColor,
                              fontSize: 24,
                              fontWeight: FontWeight.w600,
                            ),
                          ),
                        ),
                      ),
                      Expanded(
                        child: Text(
                          widget.data['yi'],
                          style: TextStyle(
                            color: _mainColor,
                            fontSize: 15,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                      ),
                      SizedBox(width: 15)
                    ],
                  ),
                ),
                Container(
                  decoration: BoxDecoration(
                    border: Border(
                      bottom: BorderSide(
                        color: _mainColor,
                        width: 2,
                        style: BorderStyle.solid,
                      ),
                      right: BorderSide(
                        color: _mainColor,
                        width: 2,
                        style: BorderStyle.solid,
                      ),
                      left: BorderSide(
                        color: _mainColor,
                        width: 2,
                        style: BorderStyle.solid,
                      ),
                    ),
                  ),
                  child: Row(
                    children: [
                      Container(
                        width: 40,
                        height: 40,
                        margin: EdgeInsets.all(15),
                        decoration: BoxDecoration(
                          color: Color(0xFFEE1000),
                          borderRadius: BorderRadius.circular(100),
                        ),
                        child: Center(
                          child: Text(
                            '忌',
                            style: TextStyle(
                              color: _bgColor,
                              fontSize: 24,
                              fontWeight: FontWeight.w600,
                            ),
                          ),
                        ),
                      ),
                      Expanded(
                        child: Text(
                          widget.data['ji'],
                          style: TextStyle(
                            color: _mainColor,
                            fontSize: 15,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                      ),
                      SizedBox(width: 15)
                    ],
                  ),
                ),
                Column(children: listRender(widget.data['details'])),
                Bottom(scjr: widget.data['scjr'])
              ],
            ),
          );
  }
}
